package com.eaglefly.redis.core;

import org.redisson.Redisson;
import org.redisson.client.codec.Codec;

import java.lang.reflect.Proxy;

/**
 * 功能：daoProxy工厂类
 * 时间：2018/1/5 11:20
 *
 * @author zhaojinpeng
 */
public class DaoProxyFactory {

    protected Object newInstance(Class daoInterface, DaoProxy daoProxy) {
        return Proxy.newProxyInstance(daoInterface.getClassLoader(), new Class[]{daoInterface}, daoProxy);
    }

    public <I, S> I newInstance(Redisson redisson, Class<I> daoInterface, Class<S> superInterface, String redisKey, Codec codec) {
        DaoProxy daoProxy = new DaoProxy(redisson, daoInterface, superInterface, redisKey, codec);
        return (I) newInstance(daoInterface, daoProxy);
    }
}
